package juc.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author fangbin
 * @desc 可重入锁演示订票 1
 * @date 2020/6/12 18:50
 */
public class BookSeat {

    public  static ReentrantLock reentrantLock = new ReentrantLock();

    public static void bookSeat(){
        reentrantLock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"开始预定座位");
            Thread.sleep(400);
            System.out.println(Thread.currentThread().getName()+"完成预定座位");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            reentrantLock.unlock();
        }
    }

    public static void main(String[] args) {

        new Thread(()->bookSeat()).start();
        new Thread(()->bookSeat()).start();
        new Thread(()->bookSeat()).start();
        new Thread(()->bookSeat()).start();
    }
}
